public class Test1 {
    public static void main(String[] args) {
        StringBuffer stringBuffer = new StringBuffer("Hello");
        stringBuffer.insert(1,"abc");
        System.out.println(stringBuffer);
        stringBuffer.delete(1,3);//左闭右开
        System.out.println(stringBuffer);
        stringBuffer.reverse();//将字符串进行翻转
        System.out.println(stringBuffer);
    }
    public static void main3(String[] args) {
        //获取开始时间
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);//获取运行完成所需要的时间

        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

    }

    public static void main2(String[] args) {
        String str = "";
        for (int i = 0; i < 1000; i++) {
            str += i;
        }
        System.out.println(str);
    }
    public static void main1(String[] args) {
        String str = "hello";
        str += "world";
        System.out.println(str);
        //上面的写法其实就相当于下面的写法
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("hello");
        stringBuilder.append("world");
        String str1 = stringBuilder.toString();//共建了4个对象
        System.out.println(str1);
    }
}
